<?php

namespace App\Admin\Controllers\Product;

use App\Extends\BaseController;
use App\Requests\Product\CategoryRequest;
use App\Services\Product\CategoryService;

class CategoryController extends BaseController
{
    public function __construct(CategoryService $service)
    {
        parent::__construct($service);
        $this->service = $service;
    }

    /**
     * 显示资源列表
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(): \Illuminate\Http\JsonResponse
    {
        return $this->success($this->service->getMenuTreeList());
    }

    /**
     * 保存新建资源
     * @param MenuRequest $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function store(CategoryRequest $request): \Illuminate\Http\JsonResponse
    {
        return $this->success($this->service->create($request->all()));
    }

    /**+
     * 显示指定资源
     *
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function show($id): \Illuminate\Http\JsonResponse
    {
        return $this->success($this->service->find($id));
    }

    /**
     * 更新指定资源
     * @param MenuRequest $request
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function update(CategoryRequest $request, $id): \Illuminate\Http\JsonResponse
    {
        return $this->success($this->service->update($id, $request->all()));
    }

    /**
     * 删除指定资源
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function destroy($id): \Illuminate\Http\JsonResponse
    {
        return $this->success($this->service->delete($id));
    }
}
